#!/bin/sh
# Sentinel - IRC Statistical and Operator Services
# chksentinel - Sentinel crontab script
#
# Copyright W. Campbell and others.  See README for more details
# Some code Copyright: Jonathan George, Kai Seidler, ircd-hybrid Team,
#                      IRCnet IRCD developers.
#
# $Id: chksentinel 7 2010-02-01 19:17:42Z dubkat $

# To check for your every 10 minutes, put the following line in your
# crontab:
#    0,10,20,30,40,50 * * * *   /home/mydir/chksentinel
# And if you don't want to get email from crontab when it checks,
# put the following in your crontab:
#    0,10,20,30,40,50 * * * *   /home/mydir/chksentinel >/dev/null 2>&1

# change this to the directory you run your ircd from:
sentineldir=/home/mydir/Sentinel

cd $sentineldir
if test -r etc/sentinel.pid; then
  # there is a pid file -- is it current?
  sentinelpid=`cat etc/sentinel.pid`
  if `kill -CHLD $sentinelpid >/dev/null 2>&1`; then
    # it's still going
    echo "Found Sentinel running."
    # back out quietly
    exit 0
  fi
  echo ""
  echo "Stale sentinel.pid file (erasing it)" 
  rm -f etc/sentinel.pid
fi
echo ""
echo "Couldn't find Sentinel running.  Reloading it..."
echo ""
# Check for conffile first
if test -r etc/sentinel.cfg; then
   # It's there, load Sentinel
  bin/sentinel
  exit 0
fi

# Well, nothing to work with...
echo "Could not reload Sentinel.."
exit 0
